package org.csu.mybigpro.controller;

import org.csu.mybigpro.service.VisualSceneService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/scenes")
public class VisualSceneController {

    @Autowired
    private VisualSceneService visualSceneService;

    @PostMapping("/generate")
    public ResponseEntity<?> generateScene(@RequestBody Map<String, String> payload) {
        String description = payload.get("description");
        if (description == null || description.isBlank()) {
            return ResponseEntity.badRequest().body(Map.of("error", "Scene description cannot be empty."));
        }
        try {
            // 添加一些风格化的提示词，让图片效果更好
            String enhancedPrompt = description + ", cinematic lighting, ultra-realistic, 8k, photorealistic";
            String base64Image = visualSceneService.generateScene(enhancedPrompt);
            return ResponseEntity.ok(Map.of("image", base64Image));
        } catch (Exception e) {
            e.printStackTrace();
            return ResponseEntity.internalServerError().body(Map.of("error", e.getMessage()));
        }
    }
}